package service.sys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.BaseMapper;
import com.common.BaseService;

import mapper.sys.RoleFunMapper;

@Service
@Transactional
public class RoleFunServiceImpl <T> extends BaseService<T>{
	@Autowired
	private RoleFunMapper roleFunMapper;

	public List<Map> getByRoleid(String uid){
		List<Map> m = roleFunMapper.getByRoleid(uid);
		return m;
	}
	
	public void saveRoleFun(String roleid,String[] ids){
		roleFunMapper.delRoleFun(roleid);
		if(ids.length>0){
			List<Map> list = new ArrayList<>();
			for(String s : ids){
				Map m = new HashMap();
				m.put("id", UUID.randomUUID().toString());
				m.put("roleid", roleid);
				m.put("funid", s);
				list.add(m);
			}
			roleFunMapper.saveRoleFun(list);
		}
	}
	
	@Override
	public BaseMapper<T> getMapper() {
		return roleFunMapper;
	}
}
